/*
 * Created on 04.07.2006 by leck
 *
 */
package de.devisnik.eidle.util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import de.devisnik.eidle.EidleActivator;
import de.devisnik.eidle.screen.IScreen;
import de.devisnik.eidle.screen.IScreenListener;

public abstract class AbstractScreen implements IScreen {

	private final String itsName;

	public AbstractScreen(final String name) {
		this.itsName = name;
	}

	public String getName() {
		return itsName;
	}

	private final List/* <IScreenListener> */itsScreenListeners = new ArrayList/* <IScreenListener> */();

	public void addScreenListener(final IScreenListener screenListener) {
		itsScreenListeners.add(screenListener);
	}

	public void removeScreenListener(final IScreenListener screenListener) {
		itsScreenListeners.remove(screenListener);
	}

	protected void fireScreenDone() {
		final String message = getClass().getName() + ": fireScreenDone at "
				+ Calendar.getInstance().getTime();
		EidleActivator.getDefault().log(message);
		final IScreenListener[] screenListeners = (IScreenListener[]) itsScreenListeners
				.toArray(new IScreenListener[itsScreenListeners.size()]);
		for (int i = 0; i < screenListeners.length; i++) {
			screenListeners[i].done(this);
		}
	}
}
